﻿using INTEX.SCHEDULER;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class UITMKRF:ViewBase
    {
       
         public StackPanel STKMachineTable
        {
            get;
            set;
        }
        public StackPanel STKmachines
        {
            get;
            set;
        }
        public StackPanel STKZoneCalendar
        {
            get;
            set;
        }
        #region ==IsMachineType===========
        public static readonly DependencyProperty IsMachineTypeProperty = DependencyProperty.Register("IsMachineType",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsMachineTypeChanged));
        public bool IsMachineType
        {
            get
            {
                return (bool)GetValue(IsMachineTypeProperty);
            }
            set
            {
                SetValue(IsMachineTypeProperty, value);
            }
        }
        private static void OnIsMachineTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.IsMachineType = (bool)e.NewValue;
            }
        }
       
        #endregion
        #region ==IsShowGantt===========
        public static readonly DependencyProperty IsShowGanttProperty = DependencyProperty.Register("IsShowGantt",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsShowGanttChanged));
        public bool IsShowGantt
        {
            get
            {
                return (bool)GetValue(IsShowGanttProperty);
            }
            set
            {
                SetValue(IsShowGanttProperty, value);
                this.Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new BOOLDelegate(OnShowGanttChg),value);
                //NormalTask = System.Threading.Tasks.Task.Factory.StartNew(() => OnShowGanttChg(value), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
        private static void OnIsShowGanttChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.IsShowGantt = (bool)e.NewValue;
            }
        }
        
        #endregion
        #region ==ShowAllMachine===========
        public static readonly DependencyProperty ShowAllMachineProperty = DependencyProperty.Register("ShowAllMachine",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnShowAllMachineChanged));
        public bool ShowAllMachine
        {
            get
            {
                return (bool)GetValue(ShowAllMachineProperty);
            }
            set
            {
                SetValue(ShowAllMachineProperty, value);
                OnShowAllChg(value);
            }
        }
        private static void OnShowAllMachineChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.ShowAllMachine = (bool)e.NewValue;
            }
        }
         
        #endregion
        #region ==ShowWJobs===========
        public static readonly DependencyProperty ShowWJobsProperty = DependencyProperty.Register("ShowWJobs",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnShowWJobsChanged));
        public bool ShowWJobs
        {
            get
            {
                return (bool)GetValue(ShowWJobsProperty);
            }
            set
            {
                SetValue(ShowWJobsProperty, value);
                OnShowWJobChg(value);
            }
        }
        private static void OnShowWJobsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.ShowWJobs = (bool)e.NewValue;
            }
        }
        
        #endregion

        #region ==ABF===========
        public static readonly DependencyProperty ABFProperty = DependencyProperty.Register("ABF",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFChanged));
        public string ABF
        {
            get
            {
                return (string)GetValue(ABFProperty);
            }
            set
            {
                SetValue(ABFProperty, value);
                OnABFChg(value); 
            }
        }
        private static void OnABFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.ABF = (string)e.NewValue;
            }
        }
        public virtual void OnABFChg(string abf)
        { 
        }
        #endregion
        #region ==dwMKRF===========
        public static readonly DependencyProperty dwMKRFProperty = DependencyProperty.Register("dwMKRF",
            typeof(DataRow), typeof(UITMKRF),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwMKRFChanged));
        public DataRow dwMKRF
        {
            get
            {
                return (DataRow)GetValue(dwMKRFProperty);
            }
            set
            {
                SetValue(dwMKRFProperty, value);
            }
        }
        private static void OndwMKRFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.dwMKRF = (DataRow)e.NewValue;
            }
        }
        #endregion

        

        #region ==JOBTYPE===========

        public static readonly DependencyProperty JOBTYPEProperty = DependencyProperty.Register("JOBTYPE",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJOBTYPEChanged));
        public string JOBTYPE
        {
            get
            {
                return (string)GetValue(JOBTYPEProperty);
            }
            set
            {
                SetValue(JOBTYPEProperty, value);
            }
        }
        private static void OnJOBTYPEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.JOBTYPE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KSTKRS===========
        public static readonly DependencyProperty KSTKRSProperty = DependencyProperty.Register("KSTKRS",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTKRSChanged));
        public string KSTKRS
        {
            get
            {
                return (string)GetValue(KSTKRSProperty);
            }
            set
            {
                SetValue(KSTKRSProperty, value);
            }
        }
        private static void OnKSTKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.KSTKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KST===========
        public static readonly DependencyProperty KSTProperty = DependencyProperty.Register("KST",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTChanged));
        public string KST
        {
            get
            {
                return (string)GetValue(KSTProperty);
            }
            set
            {
                SetValue(KSTProperty, value);
            }
        }
        private static void OnKSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.KST = (string)e.NewValue;
            }
        }
        #endregion


        #region ==AGANG===========
        public static readonly DependencyProperty AGANGProperty = DependencyProperty.Register("AGANG",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAGANGChanged));
        public string AGANG
        {
            get
            {
                return (string)GetValue(AGANGProperty);
            }
            set
            {
                SetValue(AGANGProperty, value);
            }
        }
        private static void OnAGANGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.AGANG = (string)e.NewValue;
            }
        }
        #endregion

        #region ==JOBID===========
        public static readonly DependencyProperty JOBIDProperty = DependencyProperty.Register("JOBID",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnJOBIDChanged));
        public string JOBID
        {
            get
            {
                return (string)GetValue(JOBIDProperty);
            }
            set
            {
                SetValue(JOBIDProperty, value);
                OnJOBIDChg(value);
            }
        }
        private static void OnJOBIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.JOBID = (string)e.NewValue;
            }
        }
       
        #endregion

        #region ==MACHINEID===========
        public static readonly DependencyProperty MACHINEIDProperty = DependencyProperty.Register("MACHINEID",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMACHINEIDChanged));
        public string MACHINEID
        {
            get
            {
                return (string)GetValue(MACHINEIDProperty);
            }
            set
            {
                SetValue(MACHINEIDProperty, value);
            }
        }
        private static void OnMACHINEIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.MACHINEID = (string)e.NewValue;
            }
        }
        #endregion

        #region ==MKFTP===========
        public static readonly DependencyProperty MKFTPProperty = DependencyProperty.Register("MKFTP",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMKFTPChanged));
        public string MKFTP
        {
            get
            {
                return (string)GetValue(MKFTPProperty);
            }
            set
            {
                SetValue(MKFTPProperty, value);
            }
        }
        private static void OnMKFTPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.MKFTP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AMTYP===========
        public static readonly DependencyProperty AMTYPProperty = DependencyProperty.Register("AMTYP",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAMTYPChanged));
        public string AMTYP
        {
            get
            {
                return (string)GetValue(AMTYPProperty);
            }
            set
            {
                SetValue(AMTYPProperty, value);
            }
        }
        private static void OnAMTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.AMTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==EnvType===========
        public static readonly DependencyProperty EnvTypeProperty = DependencyProperty.Register("EnvType",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEnvTypeChanged));
        public string EnvType
        {
            get
            {
                return (string)GetValue(EnvTypeProperty);
            }
            set
            {
                SetValue(EnvTypeProperty, value);
            }
        }
        private static void OnEnvTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.EnvType = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SQTY===========
        public static readonly DependencyProperty SQTYProperty = DependencyProperty.Register("SQTY",
            typeof(double), typeof(UITMKRF),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSQTYChanged));
        public double SQTY
        {
            get
            {
                return (double)GetValue(SQTYProperty);
            }
            set
            {
                SetValue(SQTYProperty, value);
            }
        }
        private static void OnSQTYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.SQTY = (double)e.NewValue;
            }
        }
        #endregion
        #region ==GDays===========
        public static readonly DependencyProperty GDaysProperty = DependencyProperty.Register("GDays",
            typeof(double), typeof(UITMKRF),
            new FrameworkPropertyMetadata(120.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnGDaysChanged));
        public double GDays
        {
            get
            {
                return (double)GetValue(GDaysProperty);
            }
            set
            {
                SetValue(GDaysProperty, value);
                OnGDaysChg();
            }
        }
        private static void OnGDaysChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.GDays = (double)e.NewValue;
            }
        }
        public virtual void OnGDaysChg()
        {
            Scheduler.GDays = GDays;
        }
        #endregion

        #region ==HistoryDays===========
        public static readonly DependencyProperty HistoryDaysProperty = DependencyProperty.Register("HistoryDays",
            typeof(double), typeof(UITMKRF),
            new FrameworkPropertyMetadata(90.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnHistoryDaysChanged));
        public double HistoryDays
        {
            get
            {
                return (double)GetValue(HistoryDaysProperty);
            }
            set
            {
                SetValue(HistoryDaysProperty, value);
                OnHistoryDaysChg();
            }
        }
        private static void OnHistoryDaysChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.HistoryDays = (double)e.NewValue;
            }
        }
        public virtual void OnHistoryDaysChg()
        {
            Scheduler.HistoryDays = HistoryDays;
        }
        #endregion

        #region ==DENSITY===========
        public static readonly DependencyProperty DENSITYProperty = DependencyProperty.Register("DENSITY",
            typeof(int), typeof(UITMKRF),
            new FrameworkPropertyMetadata(8, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDENSITYChanged));
        public int DENSITY
        {
            get
            {
                return (int)GetValue(DENSITYProperty);
            }
            set
            {
                SetValue(DENSITYProperty, value);
                OnDENSITYChg(value);            }
        }
        private static void OnDENSITYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.DENSITY = (int)e.NewValue;
            }
        }
        public virtual void OnDENSITYChg(double value)
        {
            if (Scheduler == null)
                return;
            Scheduler.GDensity = DENSITY;
            
        }
        #endregion

        #region ==IsAV===========
        public static readonly DependencyProperty IsAVProperty = DependencyProperty.Register("IsAV",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAVChanged));
        public bool IsAV
        {
            get
            {
                return (bool)GetValue(IsAVProperty);
            }
            set
            {
                SetValue(IsAVProperty, value);
            }
        }
        private static void OnIsAVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.IsAV = (bool)e.NewValue;
            }
        }

        #endregion

        #region ==IsSP===========
        public static readonly DependencyProperty IsSPProperty = DependencyProperty.Register("IsSP",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsSPChanged));
        public bool IsSP
        {
            get
            {
                return (bool)GetValue(IsSPProperty);
            }
            set
            {
                SetValue(IsSPProperty, value);
            }
        }
        private static void OnIsSPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.IsSP = (bool)e.NewValue;
            }
        }

        #endregion

        #region ==zAV33Height===========
        public static readonly DependencyProperty zAV33HeightProperty = DependencyProperty.Register("zAV33Height",
            typeof(double), typeof(UITMKRF),
            new FrameworkPropertyMetadata(400.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnzAV33HeightChanged));
        public double zAV33Height
        {
            get
            {
                return (double)GetValue(zAV33HeightProperty);
            }
            set
            {
                SetValue(zAV33HeightProperty, value);
            }
        }
        private static void OnzAV33HeightChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.zAV33Height = (double)e.NewValue;
            }
        }
        #endregion
        #region ==FTAUTOSPLIT===========
        public static readonly DependencyProperty FTAUTOSPLITProperty = DependencyProperty.Register("FTAUTOSPLIT",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFTAUTOSPLITChanged));
        public bool FTAUTOSPLIT
        {
            get
            {
                return (bool)GetValue(FTAUTOSPLITProperty);
            }
            set
            {
                SetValue(FTAUTOSPLITProperty, value);
                TMV.FTAUTOSPLIT = value;
            }
        }
        private static void OnFTAUTOSPLITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.FTAUTOSPLIT = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsRestart===========
        public static readonly DependencyProperty IsRestartProperty = DependencyProperty.Register("IsRestart",
            typeof(bool), typeof(UITMKRF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsRestartChanged));
        public bool IsRestart
        {
            get
            {
                return (bool)GetValue(IsRestartProperty);
            }
            set
            {
                SetValue(IsRestartProperty, value);
            }
        }
        private static void OnIsRestartChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.IsRestart = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==AMKST===========
        public static readonly DependencyProperty AMKSTProperty = DependencyProperty.Register("AMKST",
            typeof(string), typeof(UITMKRF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAMKSTChanged));
        public string AMKST
        {
            get
            {
                return (string)GetValue(AMKSTProperty);
            }
            set
            {
                SetValue(AMKSTProperty, value);
                OnAMKSTChg(value);
            }
        }
        private static void OnAMKSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UITMKRF;
            if (src != null)
            {
                src.AMKST = (string)e.NewValue;
            }
        }
        public virtual void OnAMKSTChg(string value)
        { }
        #endregion

        public UITMKRF()
        {
         
            
        }
        public VICC_MKRF TMV
        {
            get
            {
                return (VICC_MKRF)MV;
            }
        }

       
        public int lastDen = 24;
        public UIJOB Lastjob;

        public ITXSSPA Scheduler
        {
            get
            {
                return TMV.Scheduler;
            }
        }
       
        
        public NameScope pagescope = new System.Windows.NameScope();
     
  
        public Dictionary<string, UIAM> MachinesLib
        {
            get
            {
                return Scheduler.MachinesLib;
            }
        }
        public Dictionary<string, object> JobsLib
        {
            get
            {
                return TMV.JobsLib;
            }
        } 
       
       
     
    }
}
